package com.acme.domain.bank;

import java.io.Serializable;
import java.util.Date;

import com.acme.domain.client.Client;
import com.acme.listeners.ClientRegistrationListener;

public class Bank implements Serializable
{
	private static final long serialVersionUID = 1L;
	
	private final Client[] clients;
	private int maxClients = 0;
	private ClientRegistrationListener[] listeners;

	public Bank(final int bankSize,
			ClientRegistrationListener[] crls)
	{
		clients = new Client[bankSize];
		listeners = crls;
	}

	private class DebugListener implements ClientRegistrationListener
	{
		private Date now = new Date();
		
		public void onClientAdded(Client client)
		{
			System.out.println("Date:\t" + now + "\n");
		}
	};
	
	public Client addClient(final Client newClient)
	{
		clients[maxClients++] = newClient;			
		for (ClientRegistrationListener crl : listeners)
		{
			crl.onClientAdded(newClient);
		}
		(new DebugListener()).onClientAdded(newClient);		
		return newClient;
	}
	
	public int getBankSize()
	{
		return maxClients;
	}
}
